home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / get_text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  5.1 KB  |  177 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: get_text.c,v 1.1 89/03/17 08:21:10 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/get_text.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/get_text.c,v $$Revision: 1.1 $";
  12.  
  13. /* sweep out text rectangle */
  14.  
  15. #include <stdio.h>
  16. #include "bitmap.h"
  17. #include "defs.h"
  18. #include "font.h"
  19. #include "event.h"
  20.  
  21. #define FSIZE(c)    ((int) (W(font)->head.c))
  22. #define THICK    2
  23.  
  24. #define TOP    1
  25. #define MIDDLE    2
  26. #define BOTTOM    3
  27. #define ALL    4
  28.  
  29. int
  30. get_text(screen,mouse,x,y,dx,dy,win,c)
  31. BITMAP *screen;        /* where to sweep out the box */
  32. int mouse;            /* file to get mouse coords from */
  33. int x,y;            /* starting position */
  34. register int *dx,*dy;        /* box width,height */
  35. WINDOW *win;            /* text window */
  36. int c;                /* E_SWTEXT or E_SWTEXTT */
  37.    {
  38.    register int button;
  39.    int left,top;
  40.    int cols,rows;
  41.    int gx,gy;
  42.    int x_mouse, y_mouse;
  43.    int lastdx, lastdy;                /* previous dx,dy */
  44.     int newx = *dx * FSIZE(wide);
  45.     int newy = *dy * FSIZE(high);  
  46.    rectangle text;
  47.  
  48.    /* set up text regions */
  49.  
  50.    if (c == E_SWTEXT)                /* no text region */
  51.       text.x = text.y = text.wide = text.high = 0;
  52.    else if (!in_text(x,y,win)) {
  53.       button=move_mouse(screen,mouse,&mousex,&mousey,1);
  54.       return(0);
  55.       }
  56.    else 
  57.       text = W(text);
  58.  
  59.    left = W(x0) + SUM_BDR + text.x;    /* edge of window (pixels) */
  60.    top = W(y0) + SUM_BDR + text.y;    /* top of window (pixels) */
  61.    cols = (text.wide ? text.wide : BIT_WIDE(W(window)))/FSIZE(wide);
  62.    rows = (text.wide ? text.high : BIT_HIGH(W(window)))/FSIZE(high);
  63.    gx = FSIZE(wide);            /* char width (pixels) */
  64.    gy = FSIZE(high);            /* char height (pixels) */
  65.  
  66.    x = (x-left)/gx;
  67.    y = (y-top)/gy;
  68.  
  69.    do_box(screen,x,y,dx,dy,top,left,cols,rows,gx,gy);     /* on */
  70.    do {
  71.       button=mouse_get(mouse,&x_mouse,&y_mouse);
  72.       newx += x_mouse<<1;
  73.       newy -= y_mouse<<1;
  74.       lastdx = *dx, *dx = newx/gx;
  75.       lastdy = *dy ,*dy = newy/gy;
  76.       if (lastdx != *dx || lastdy != *dy) {
  77.          do_box(screen,x,y,&lastdx,&lastdy,top,left,cols,rows,gx,gy);    /* off*/
  78.          if (do_box(screen,x,y,dx,   dy,   top,left,cols,rows,gx,gy))    /* on */
  79.             newx = gx * *dx,  newy = gy * *dy;
  80.          }
  81.       }
  82.    while (button!=0);
  83.  
  84.    do_box(screen,x,y,dx,dy,top,left,cols,rows,gx,gy);            /* off*/
  85.    return(1);
  86.    }
  87.  
  88. /* piece boxes */
  89.  
  90. int
  91. do_box(screen,x1,y1,px,py,top,left,cols,rows,gx,gy)
  92. BITMAP *screen;
  93. int x1,y1;        /* starting pos in rows/cols */
  94. int *px,*py;        /* ending delta in rows/cols */
  95. int top,left;        /* start of window in pixels */
  96. int cols,rows;        /* size of window */
  97. int gx,gy;        /* character size (in pixels) */
  98.    {
  99.    register int dx = *px;
  100.    register int dy = *py;
  101.  
  102.    if (dy < 0)
  103.       dy = 0;
  104.  
  105.    if (dy == 0 && dx < 0)
  106.       dx = 0;
  107.  
  108.    if (x1 + dx < 0)
  109.       dx = -x1;
  110.  
  111.    if (x1+dx > cols)
  112.       dx = cols-x1;
  113.  
  114.    if (y1+ dy >= rows)
  115.       dy = rows-y1-1;
  116.  
  117.    switch(dy) {
  118.       case 0:        /* 1 line */
  119.          tbox(screen, left+x1*gx-1, top+y1*gy-2,   dx*gx,       gy+3, ALL);
  120.          break;
  121.       case 1:        /* two lines */
  122.          tbox(screen, left+x1*gx-1, top+y1*gy-2,       (cols-x1)*gx,  gy+2, TOP);
  123.          tbox(screen, left-1,       top + (y1+1)*gy, (x1+dx)*gx,    gy+1, BOTTOM);
  124.          break;
  125.       default:        /* many lines */
  126.          tbox(screen, left+x1*gx-1, top + y1*gy-2,      (cols-x1)*gx, gy+2, TOP);
  127.          tbox(screen, left-1,       top + (y1+1)*gy,  cols*gx,      (dy-1)*gy, MIDDLE);
  128.          tbox(screen, left-1,       top + (y1+dy)*gy, (x1+dx)*gx,   gy+1, BOTTOM);
  129.          break;
  130.       }
  131.    if (*px != dx || *py != dy) {
  132.       *px = dx; *py = dy;
  133.       return(1);
  134.       }
  135.    else
  136.       return(0);
  137.    }
  138.  
  139. /* draw a box */
  140.  
  141. #define INVERT(screen,x,y,wide,high) \
  142.     bit_blit(screen,x,y,wide,high,BIT_NOT(BIT_DST),NULL_DATA,0,0);
  143.  
  144. static
  145. tbox(screen,x1,y1,dx,dy,side)
  146. BITMAP *screen;
  147. int x1,y1,dx,dy;
  148. int side;
  149.    {
  150.    switch (side) {
  151.       case TOP:
  152.          INVERT(screen,x1,y1,dx,THICK);
  153.          INVERT(screen,x1+dx,y1,THICK, dy);
  154.          INVERT(screen,x1+THICK,y1+dy,dx-THICK,THICK);
  155.          INVERT(screen,x1,y1+THICK,THICK, dy-THICK);
  156.          break;
  157.       case MIDDLE:
  158.          INVERT(screen,x1+THICK,y1,dx-THICK,THICK);
  159.          INVERT(screen,x1+dx,y1+THICK,THICK, dy-THICK);
  160.          INVERT(screen,x1+THICK,y1+dy,dx-THICK,THICK);
  161.          INVERT(screen,x1,y1+THICK,THICK, dy-THICK);
  162.          break;
  163.       case BOTTOM:
  164.          INVERT(screen,x1+THICK,y1,dx-THICK,THICK);
  165.          INVERT(screen,x1+dx,y1+THICK,THICK, dy-THICK);
  166.          INVERT(screen,x1+THICK,y1+dy,dx,THICK);
  167.          INVERT(screen,x1,y1+THICK,THICK, dy);
  168.          break;
  169.       case ALL:
  170.          INVERT(screen,x1,y1,dx,THICK);
  171.          INVERT(screen,x1+dx,y1,THICK, dy);
  172.          INVERT(screen,x1+THICK,y1+dy,dx,THICK);
  173.          INVERT(screen,x1,y1+THICK,THICK, dy);
  174.          break;
  175.       }
  176.    }
  177.